<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 */

class Gio_Core_Module
{
	public static function getAllModules($notIn = array())
	{
		$modules = array();
		$modulesDir = ROOT_DIR . DS . 'modules';
		if (!file_exists($modulesDir)) {
			return $modules;
		}
		$modulesIterator = new DirectoryIterator($modulesDir);
		foreach ($modulesIterator as $module) {
			if ($module->isDot() || in_array($module, $notIn)) {
				continue;
			}
			$moduleName = $module->getFilename();
			if (('CVS' == $moduleName) || ('.svn' == strtolower($moduleName)) 
					|| ('index.html' == $moduleName)
					|| ('.htaccess' == $moduleName)) {
                continue;
            }
            
            $modules[] = $moduleName;
		}
		return $modules;
	}
	
	public static function getAboutModule($name, $section = null)
	{
		$moduleDir = ROOT_DIR . DS . 'modules' . DS . $name;
		$aboutFileXml = $moduleDir . DS . 'configs'. DS . 'about.xml';
		if (!file_exists($aboutFileXml)) {
			return;
		}
		$aboutXml = @simplexml_load_file($aboutFileXml);
		if ($section) {
			return $aboutXml->admin->{$section};
		}
		return $aboutXml->admin;
	}
	
	public static function getConfig($module, $section = true)
	{
		$configFile = MOD_DIR . DS . $module . DS . 'configs' . DS . 'config.ini';
		if (file_exists($configFile)) {
			$iniArray = @parse_ini_file($configFile, $section);
			return $iniArray;
		}
		return array();
	}
}